package.preload['framework.constant']=(function(...)
local e={
HTTPMETHOD={
GET="get",
POST="post",
HEAD="head",
PUT="put",
DELETE="delete",
PATCH="patch",
OPTIONS="options",
OPTIONS="options"
}
}
return e
end)
package.preload['framework.lua_ex']=(function(...)
function printLog(e,t,...)
local e={
"[",
string.upper(tostring(e)),
"] ",
string.format(tostring(t),...)
}
print(table.concat(e))
end
function printError(e,...)
printLog("ERR",e,...)
print(debug.traceback("",2))
end
function printInfo(e,...)
if type(DEBUG)~="number"or DEBUG<2 then return end
printLog("INFO",e,...)
end
local function t(e)
if type(e)=="string"then
e="\""..e.."\""
end
return tostring(e)
end
function dump(c,u,n)
if type(n)~="number"then n=3 end
local l={}
local e={}
local a=string.split(debug.traceback("",2),"\n")
print("dump from: "..string.trim(a[3]))
local function r(i,a,o,d,h)
a=a or"<var>"
local s=""
if type(h)=="number"then
s=string.rep(" ",h-string.len(t(a)))
end
if type(i)~="table"then
e[#e+1]=string.format("%s%s%s = %s",o,t(a),s,t(i))
elseif l[tostring(i)]then
e[#e+1]=string.format("%s%s%s = *REF*",o,t(a),s)
else
l[tostring(i)]=true
if d>n then
e[#e+1]=string.format("%s%s = *MAX NESTING*",o,t(a))
else
e[#e+1]=string.format("%s%s = {",o,t(a))
local h=o.."    "
local a={}
local n=0
local s={}
for e,o in pairs(i)do
a[#a+1]=e
local t=t(e)
local t=string.len(t)
if t>n then n=t end
s[e]=o
end
table.sort(a,function(e,t)
if type(e)=="number"and type(t)=="number"then
return e<t
else
return tostring(e)<tostring(t)
end
end)
for a,t in ipairs(a)do
r(s[t],t,h,d+1,n)
end
e[#e+1]=string.format("%s}",o)
end
end
end
r(c,u,"- ",1)
for t,e in ipairs(e)do
print(e)
end
end
function printf(e,...)
print(string.format(tostring(e),...))
end
function checknumber(e,t)
return tonumber(e,t)or 0
end
function checkint(e)
return math.round(checknumber(e))
end
function checkbool(e)
return(e~=nil and e~=false)
end
function checktable(e)
if type(e)~="table"then e={}end
return e
end
function isset(e,a)
local t=type(e)
return(t=="table"or t=="userdata")and e[a]~=nil
end
local o
o=function(t,a)
if type(t)=="userdata"then
local e=tolua.getpeer(t)
if not e then
e={}
tolua.setpeer(t,e)
end
o(e,a)
else
local e=getmetatable(t)
if not e then e={}end
if not e.__index then
e.__index=a
setmetatable(t,e)
elseif e.__index~=a then
o(e,a)
end
end
end
setmetatableindex=o
function clone(i)
local t={}
local function o(e)
if type(e)~="table"then
return e
elseif t[e]then
return t[e]
end
local a={}
t[e]=a
for t,e in pairs(e)do
a[o(t)]=o(e)
end
return setmetatable(a,getmetatable(e))
end
return o(i)
end
function class(o,...)
local e={__cname=o}
local t={...}
for a,t in ipairs(t)do
local a=type(t)
assert(a=="nil"or a=="table"or a=="function",
string.format("class() - create class \"%s\" with invalid super class type \"%s\"",
o,a))
if a=="function"then
assert(e.__create==nil,
string.format("class() - create class \"%s\" with more than one creating function",
o));
e.__create=t
elseif a=="table"then
if t[".isclass"]then
assert(e.__create==nil,
string.format("class() - create class \"%s\" with more than one creating function or native class",
o));
e.__create=function()return t:create()end
else
e.__supers=e.__supers or{}
e.__supers[#e.__supers+1]=t
if not e.super then
e.super=t
end
end
else
error(string.format("class() - create class \"%s\" with invalid super type",
o),0)
end
end
e.__index=e
if not e.__supers or#e.__supers==1 then
setmetatable(e,{__index=e.super})
else
setmetatable(e,{__index=function(a,t)
local e=e.__supers
for a=1,#e do
local e=e[a]
if e[t]then return e[t]end
end
end})
end
if not e.ctor then
e.ctor=function()end
end
e.new=function(...)
local t
if e.__create then
t=e.__create(...)
else
t={}
end
setmetatableindex(t,e)
t.class=e
t:ctor(...)
return t
end
e.create=function(t,...)
return e.new(...)
end
e.name=function()
return e.__cname
end
return e
end
local a
a=function(e,t)
local o=rawget(e,"__index")
if type(o)=="table"and rawget(o,"__cname")==t then return true end
if rawget(e,"__cname")==t then return true end
local e=rawget(e,"__supers")
if not e then return false end
for o,e in ipairs(e)do
if a(e,t)then return true end
end
return false
end
function iskindof(t,i)
local o=type(t)
if o~="table"and o~="userdata"then return false end
local e
if o=="userdata"then
if tolua.iskindof(t,i)then return true end
e=tolua.getpeer(t)
else
e=getmetatable(t)
end
if e then
return a(e,i)
end
return false
end
function import(i,o)
local e
local t=i
local a=1
while true do
if string.byte(i,a)~=46 then
t=string.sub(i,a)
if e and#e>0 then
t=table.concat(e,".").."."..t
end
break
end
a=a+1
if not e then
if not o then
local t,e=debug.getlocal(3,1)
o=e
end
e=string.split(o,".")
end
table.remove(e,#e)
end
return require(t)
end
function handler(e,t)
return function(...)
return t(e,...)
end
end
function math.newrandomseed()
local t,e=pcall(function()
return require("socket")
end)
if t then
math.randomseed(e.gettime()*1e3)
else
math.randomseed(os.time())
end
math.random()
math.random()
math.random()
math.random()
end
function math.round(e)
e=checknumber(e)
return math.floor(e+.5)
end
local e=math.pi/180
function math.angle2radian(t)
return t*e
end
local t=math.pi*180
function math.radian2angle(e)
return e/t
end
function io.exists(e)
local e=io.open(e,"r")
if e then
io.close(e)
return true
end
return false
end
function io.readfile(e)
local e=io.open(e,"r")
if e then
local t=e:read("*a")
io.close(e)
return t
end
return nil
end
function io.writefile(t,a,e)
e=e or"w+b"
local e=io.open(t,e)
if e then
if e:write(a)==nil then return false end
io.close(e)
return true
else
return false
end
end
function io.pathinfo(a)
local e=string.len(a)
local t=e+1
while e>0 do
local a=string.byte(a,e)
if a==46 then
t=e
elseif a==47 then
break
end
e=e-1
end
local o=string.sub(a,1,e)
local a=string.sub(a,e+1)
t=t-e
local e=string.sub(a,1,t-1)
local t=string.sub(a,t)
return{
dirname=o,
filename=a,
basename=e,
extname=t
}
end
function io.filesize(e)
local t=false
local e=io.open(e,"r")
if e then
local a=e:seek()
t=e:seek("end")
e:seek("set",a)
io.close(e)
end
return t
end
function table.nums(t)
local e=0
for t,t in pairs(t)do
e=e+1
end
return e
end
function table.keys(t)
local e={}
for t,a in pairs(t)do
e[#e+1]=t
end
return e
end
function table.values(t)
local e={}
for a,t in pairs(t)do
e[#e+1]=t
end
return e
end
function table.merge(a,e)
for e,t in pairs(e)do
a[e]=t
end
end
function table.insertto(t,a,e)
e=checkint(e)
if e<=0 then
e=#t+1
end
local o=#a
for o=0,o-1 do
t[o+e]=a[o+1]
end
end
function table.indexof(t,a,e)
for e=e or 1,#t do
if t[e]==a then return e end
end
return false
end
function table.keyof(t,e)
for t,a in pairs(t)do
if a==e then return t end
end
return nil
end
function table.removebyvalue(o,n,i)
local a,e,t=0,1,#o
while e<=t do
if o[e]==n then
table.remove(o,e)
a=a+1
e=e-1
t=t-1
if not i then break end
end
e=e+1
end
return a
end
function table.map(e,o)
for t,a in pairs(e)do
e[t]=o(a,t)
end
end
function table.walk(t,e)
for t,a in pairs(t)do
e(a,t)
end
end
function table.filter(e,a)
for t,o in pairs(e)do
if not a(o,t)then e[t]=nil end
end
end
function table.unique(e,i)
local o={}
local a={}
local t=1
for n,e in pairs(e)do
if not o[e]then
if i then
a[t]=e
t=t+1
else
a[n]=e
end
o[e]=true
end
end
return a
end
string._htmlspecialchars_set={}
string._htmlspecialchars_set["&"]="&amp;"
string._htmlspecialchars_set["\""]="&quot;"
string._htmlspecialchars_set["'"]="&#039;"
string._htmlspecialchars_set["<"]="&lt;"
string._htmlspecialchars_set[">"]="&gt;"
function string.htmlspecialchars(e)
for t,a in pairs(string._htmlspecialchars_set)do
e=string.gsub(e,t,a)
end
return e
end
function string.restorehtmlspecialchars(e)
for t,a in pairs(string._htmlspecialchars_set)do
e=string.gsub(e,a,t)
end
return e
end
function string.nl2br(e)
return string.gsub(e,"\n","<br />")
end
function string.text2html(e)
e=string.gsub(e,"\t","    ")
e=string.htmlspecialchars(e)
e=string.gsub(e," ","&nbsp;")
e=string.nl2br(e)
return e
end
function string.split(e,t)
e=tostring(e)
t=tostring(t)
if(t=='')then return false end
local a,o=0,{}
for i,t in function()return string.find(e,t,a,true)end do
table.insert(o,string.sub(e,a,i-1))
a=t+1
end
table.insert(o,string.sub(e,a))
return o
end
function string.ltrim(e)
return string.gsub(e,"^[ \t\n\r]+","")
end
function string.rtrim(e)
return string.gsub(e,"[ \t\n\r]+$","")
end
function string.trim(e)
e=string.gsub(e,"^[ \t\n\r]+","")
return string.gsub(e,"[ \t\n\r]+$","")
end
function string.ucfirst(e)
return string.upper(string.sub(e,1,1))..string.sub(e,2)
end
local function t(e)
return"%"..string.format("%02X",string.byte(e))
end
function string.urlencode(e)
e=string.gsub(tostring(e),"\n","\r\n")
e=string.gsub(e,"([^%w%.%- ])",t)
return string.gsub(e," ","+")
end
function string.urldecode(e)
e=string.gsub(e,"+"," ")
e=string.gsub(e,"%%(%x%x)",function(e)return string.char(checknumber(e,16))end)
e=string.gsub(e,"\r\n","\n")
return e
end
function string.utf8len(e)
local t=string.len(e)
local t=t
local o=0
local a={0,192,224,240,248,252}
while t~=0 do
local i=string.byte(e,-t)
local e=#a
while a[e]do
if i>=a[e]then
t=t-e
break
end
e=e-1
end
o=o+1
end
return o
end
function string.formatnumberthousands(e)
local e=tostring(checknumber(e))
local t
while true do
e,t=string.gsub(e,"^(-?%d+)(%d%d%d)",'%1,%2')
if t==0 then break end
end
return e
end
end)
package.preload['framework.lua_ex2']=(function(...)
function c_func(t,a,...)
local e={...}
return function(...)
local e=clone(e)
table.insertto(e,{...})
if not e then
return a(t)
else
return a(t,unpack(e))
end
end
end
function func_hook(e,t,...)
if type(e[t])=="function"then
return e[t](e,...)
elseif type(e["class"])=="table"then
if type(e["class"][t])=="function"then
return e["class"][t](e,...)
end
end
end
function empty(e)
if e==''or e==0 or e=={}or e==nil then return true end
end
function table.connect(e,...)
if e and type(e)~="table"then
e={e}
end
for a,t in ipairs({...})do
if type(t)=="table"then
for a,t in ipairs(t)do
table.insert(e,t)
end
else
table.insert(e,t)
end
end
return e
end
function table.isNil(e)
if type(e)=="table"then
return not next(e)
else
return true
end
end
function table.find(e,...)
if type(e)~="table"then
return nil
end
local e=e
for a,t in ipairs({...})do
if type(t)=="string"then
for a,t in ipairs(totable(string.split(t,".")))do
if type(e)=="table"and e[t]~=nil then
e=e[t]
else
return nil
end
end
else
if type(e)=="table"and e[t]~=nil then
e=e[t]
else
return nil
end
end
end
return e
end
local function i(t,e)
e=not not e
if t then
local e=function(a,o)
local a=table.find(a,unpack(string.split(t,".")))
local t=table.find(o,unpack(string.split(t,".")))
return e and tonum(a)>tonum(t)or tonum(a)<tonum(t)
end
return e
else
local e=function(t,a)
return e and tonum(t)>tonum(a)or tonum(t)<tonum(a)
end
return e
end
end
function table.sortbykey(e,t,a)
table.sort(e,i(t,a))
end
function table.deepcopy(i)
local t={}
local function o(e)
if type(e)~="table"then
return e
elseif t[e]then
return t[e]
end
local a={}
t[e]=a
for e,t in pairs(e)do
a[o(e)]=o(t)
end
return setmetatable(a,getmetatable(e))
end
return o(i)
end
function tonum(e,t)
return tonumber(e,t)or 0
end
function toint(e)
return math.round(tonum(e))
end
function tobool(e)
return(e~=nil and e~=false)
end
function totable(e)
if type(e)~="table"then e={}end
return e
end
function catch(e)
return{catch=e[1]}
end
function try(t)
local a=t[1]
assert(a)
local e=t[2]
if e and t[3]then
table.join2(e,t[2])
end
local t,a=pcall(a)
if not t then
if e and e.catch then
e.catch(a)
end
end
if e and e.finally then
e.finally(t,a)
end
if t then
return a
end
end end)
package.preload['framework.ln']=(function(...)
local e={
_src_f=nil
}
local o={"{a}","{b}","{c}","{d}"}
function e:set_srcval(e)
self._src_f=e
end
function e.k(t,a,...)
if not e._src_f then return"unknow"end
local e=require(e._src_f)["K"]
if e[t]then
if e[t][a]then
local e=e[t][a]
if(...)then
local t={...}
for a,t in pairs(t)do
e=string.gsub(e,o[a],t)
end
end
return e
end
end
return tostring(t).."_"..tostring(a)
end
function e.g(t,...)
if not e._src_f then return"unknow"end
local a=require(e._src_f)["G"]
local e=tostring(t)
if a[t]then
e=a[t]
end
return e
end
return e
end)
package.preload['framework.cls.basehandler']=(function(...)
local e=class("BaseHandler")
local i=Ding
local a=ngx
local o=require("cjson")
local t=i.Logger
local n=i.LN
function e:ctor(a,t,e)
self._name=string.upper(a)
self._svr=t
self._defdata={}
self._apimap=e
end
function e:_is_apifunc(e)
return self._apimap[e]~=nil
end
function e:set_datadefault(e)
self._defdata=e
end
function e:apimap()
return self._apimap
end
function e:svr()
return self._svr
end
function e:name()
return self._name
end
function e:doret(e)
self._defdata["r"]=0
self._defdata["data"]=e or{}
local e=o.encode(self._defdata)
t:info("%s handler return the val->%s",self:name(),e)
a.print(e)
end
function e:doerror(e,i)
self._defdata["r"]=e
self._defdata["desc"]=i
local e=o.encode(self._defdata)
t:info("%s handler raise the err->%s",self:name(),e)
a.print(e)
end
function e:doalert(i,e)
self._defdata["r"]=e
self._defdata["desc"]=n.k(i,e)
local e=o.encode(self._defdata)
t:info("%s handler raise the err->%s",self:name(),e)
a.print(e)
end
return e
end)
package.preload['framework.cls.baseserver']=(function(...)
local e=class("BaseServer")
local t=Ding
local t=t.Logger
local o=require("resty.router")
local t=require("framework.constant").HTTPMETHOD
local function i(e)
return string.upper(e[2])..string.gsub(e[1],"/","_")
end
function e:ctor(e)
self:link_router_handler(e)
end
function e:link_router_handler(e)
local t={}
local a
for o,e in ipairs(e)do
a={e[1],i(e),e[2]}
table.insert(t,a)
end
ngx.log(ngx.DEBUG,"handler_tree:")
dump(t)
self._r=o:create(t)
end
function e:run()
self:_access_()
:_content_()
end
function e:add_apihandle(e,t)
self._api_handlers[e]=t
end
function e:_access_()
return self
end
function e:_content_()
local e=string.gsub(ngx.var.uri,ngx.var.location,'')
ngx.log(ngx.INFO,string.format("rel_path:%s, uri:%s,  location:%s",e,ngx.var.uri,ngx.var.location))
if(self._r)then
local e,t,a=self._r:match(e,ngx.req.get_method())
ngx.log(ngx.INFO,"ret"..tostring(e))
ngx.log(ngx.INFO,"err:"..tostring(t))
ngx.log(ngx.INFO,"status:"..tostring(a))
local e=c_func(self,self[e])()
dump("handler",e)
end
end
function e:_chk_routeruri(e)
local o,a
local t=ngx.var.location
local i=string.find(e,t)
if i then
o=true
a=e==t and""or string.sub(e,string.len(t))
end
return o,a
end
return e
end)
package.preload['framework.db.poolmgr']=(function(...)
local e=class("PoolMgr")
local o=Ding
function e:ctor()
end
function e:new_connect(a,e)
e=self._cfg
if not e then
return
end
local t=require(a).new()
local i,e=t:connect(e)
if i then
return t
else
o.Logger:warning("Connect to db %s failed:%s",tostring(a),tostring(e))
end
end
function e:default_dis()
end
function e:set_distrbutefunc(e)
end
function e:get_connect(t,e)
self._cfg=e
return self:new_connect(t,e)
end
function e:closeall()
for e in ipairs(self._inclist)do
e:close()
end
end
return e
end)
package.preload['framework.db.mysqlinc']=(function(...)
local e=class("MysqlInc")
local o=require("resty.mysql")
local t=Ding
local a=t.Logger
local t=t.UtilRds
local i=10*1e3
local i=10
local i=require("cjson")
e.dtype="mysql"
function e:ctor()
self._inc=o:new()
self._iscon=false
end
function e:connect(e)
local t,o=self._inc:connect(e)
self._inc:set_timeout(5e3)
if t then
self._iscon=true
return true
else
a:error("failed to connnect the mysql:%s",i.encode(e))
return false
end
end
function e:insert_data(e,a)
if self._iscon and self._inc then
local e=t.insert_data(e,a)
return self:query_cmd(e)
end
end
function e:find_all(a,e)
if self._iscon and self._inc then
local e=t.find(a,e)
return self:query_cmd(e)
end
end
function e:find_one(t,e)
local e=self:find_all(t,e)
if type(e)=="table"and#e>0 then
return e[1]
end
end
function e:find_in_set(o,a,e)
local e=t.find_in_set(o,a,e)
return self:query_cmd(e)
end
function e:find_in(e,a,o)
local e=t.find_in(e,a,o)
return self:query_cmd(e)
end
function e:dele_one(e,a)
if self._iscon and self._inc then
local e=t.dele_all(e,a)
return self:query_cmd(e)
end
end
function e:fetch_limitcnt(o,a,e)
local e=t.fetch_limitcnt(o,a,e)
return self:query_cmd(e)
end
function e:update(e,a,o,...)
local e=t.update(e,a,o,...)
return self:query_cmd(e)
end
function e:release_conn()
end
function e:transaction_cmd(t)
if not self._inc or not self._inc then return end
ret=true
ret=self:query_cmd("BEGIN")
ret=self:query_cmd("SET AUTOCOMMIT=0")
local e=true
for o,t in ipairs(t)do
if not type(cmds)=="string"then
a:error("[MYSQL queryfunc]transition values must query strings!")
break
end
if(not self:query_cmd(t))then
e=false
break
end
end
if e then
self:query_cmd("COMMIT")
else
self:query_cmd("ROLLBACK")
end
return e
end
function e:query_cmd(t)
if self._iscon and self._inc then
local e,o,i,n=self._inc:query(t)
a:debug("mysql run cmd--%s",t)
if not e then
a:error("mysql query %s raise error:%s",query_cmd,o)
return false
end
self:release_conn()
return e,o,i,n
else
a:error("Query mysql failed!No connected yet!")
end
end
function e:send_query(e)
local t,e=self._inc:send_query(e)
return t,e
end
function e:read_result()
return self._inc:read_result()
end
return e
end)
package.preload['framework.db.redisinc']=(function(...)
local e=class('RedisInc')
local a=require('resty.redis')
local t=Ding
local t=t.Logger
local h=10*1e3
local r=10
local s=require('cjson')
e.dtype='redis'
function e:ctor(e,e)
self._inc=a:new()
self._iscon=false
self._is_lazyinit=false
end
function e:connect(e)
local a,i,o=e['host'],e['port'],e['auth']
self._inc:set_timeout(self.TIMEOUT)
local n,s=self._inc:connect(a,i)
if not n then
t:error('failed to connect: %s:%s',a,i)
return false
end
if o then
local n,s=self._inc:auth(o)
if not n then
t:error('failed to auth:%s, pwd is %s',a,i,o)
return false
else
if not self._is_lazyinit then
self:_lazy_init(e)
end
end
end
self._iscon=true
return true
end
function e:close(e)
if e then
self._inc:close()
return
end
t:debug('close the redis connect!')
self._inc:set_keepalive(h,r)
end
function e:fetch_limitcnt(t,a,e)
return self:lrange(t,tonumber(a),tonumber(e))
end
function e:insert_data(t,e)
if self._iscon and self._inc then
if type(e)~='table'then
return self:mset(t,e)
else
return self._inc:hmset(t,e)
end
end
end
function e:lpush_data(t,e)
if self._iscon and self._inc then
return self:lpush(t,s.encode(e))
end
end
function e:find_one(t,e)
local a=(type(e)=='table'and#e>0)
if a then
return self._inc:hmget(t,unpack(e))
else
return self._inc:get(t)
end
end
function e:find_all(e,t)
return self:find_one(e,t)
end
function e:update(e,t)
local a=self:find_one(e)
return self._inc:insert_data(e,t)
end
function e:dele_one(e)
return self._inc:del(e)
end
function e:_lazy_init(o)
local e={
'get',
'set',
'mget',
'mset',
'del',
'incr',
'incrby',
'decr',
'llen',
'lindex',
'lpop',
'lpush',
'lrange',
'linsert',
'hexists',
'hget',
'hset',
'hmget',
'hdel',
'smembers',
'sismember',
'sadd',
'srem',
'sdiff',
'sinter',
'sunion',
'zrange',
'zrangebyscore',
'zrank',
'zadd',
'zrem',
'zincrby',
'auth',
'eval',
'expire',
'script',
'sort'
}
local a={
'subscribe',
'psubscribe',
'publish'
}
table.merge(e,a)
for a,e in ipairs(e)do
self[e]=function(a,...)
t:debug('redis on [%s:%s] cmd [%s] execute ',o['host'],o['port'],e)
return a._inc[e](a._inc,...)
end
end
self._is_lazyinit=true
end
return e
end)
package.preload['framework.db.mongoinc']=(function(...)
local e=class("MongoMgr")
local t=require("resty.mongol")
local i=10*1e3
local n=10
function e:ctor()
self._inc=t:new()
self._db=nil
self._col=nil
self._iscon=false
self._islogin=false
end
function e:connect(e)
local t,e=e["host"],e["port"]
local a=Ding
self._inc:set_timeout(self.TIMEOUT)
local o,i=self._inc:connect(t,e)
if not o then
a.Logger:error("Failed to connect: %s:%s",t,e)
return false
end
a.Logger:info("Connect to the db suc %s:%s",t,e)
self._iscon=true
return true
end
function e:close(e)
if e then
self._inc:close()
return
end
d.Logger:debug("close the mongo connect!")
self._inc:set_keepalive(i,n)
end
function e:set_dbauth(e,t)
if self:_is_db()then
self._db:auth(e,t)
end
end
function e:set_db(e)
self._db=self._inc:new_db_handle(e)
end
function e:set_col(e)
if self:_is_db()then
self._col=self._db:get_col(e)
end
return self
end
function e:set_db_col(e,t)
local e=self._inc:new_db_handle(e)
self._col=e:get_col(t)
self._db=e
return self._col
end
function e:find_one(e,t)
if self:_is_col()then
return self._col:find_one(e,t)
end
end
function e:find(a,t,e)
if self:_is_col()then
self._col:find(a,t,e)
end
end
function e:insert_data(t,a,e)
if self:_is_col()then
local o,a=self._col:insert(t,a,e)
local e=Ding
if a then
e.Logger:error("Mongodb-Col insert handle raise error!->%s\n",a)
else
e.Logger:debug("Mongodb-Col insert handle suc!%s",t)
end
if o==0 then
e.Logger:info("Col insert the data suc!")
end
else
d.Logger:error("Mongodb not choose col yet!")
end
end
function e:update(a,o,i,e,t)
if self:_is_col()then
local t,e=self._col:update(a,o,i,e,t)
if e then
d.Logger:error("Mongodb update handle raise error!->%s\n",e)
end
end
end
function e:_is_db()
return self._db~=nil
end
function e:_is_col()
return self._col~=nil
end
return e
end)
package.preload['framework.orm.init']=(function(...)
local t=class("ORM")
local e=Ding
local a=e.Logger
function t:ctor(e)
self._smap=e
self._rmap={}
end
function t:get(e)
if self._rmap[e]then return self._rmap[e]end
if not self._smap[e]then
a:error("create orm <%s> failed! not in orm mapping!",e)
return
end
local e=self._smap[e]
local t=e["src"]
local e=require(t).new(e["dccfg"])
return e
end
return t end)
package.preload['framework.orm.base']=(function(...)
local e=class('ORMBase')
local a=Ding
local t=a.Logger
local a=a.PoolMgr
local o={
mysql='framework.db.mysqlinc',
redis='framework.db.redisinc'
}
function e:ctor(e)
self._dccfg=e
local t
for e,a in pairs(e)do
t="cfg_"..e
if not self[e]then
self[t]=function(e)
return a or''
end
end
end
self._mname=modelname
self._model=nil
end
function e:_dc()
local e=self._dccfg['ctype']or'mysql'
return a:get_connect(o[e],self._dccfg)
end
function e:_dc_runcmd(a,...)
local e=self:_dc()
if not e then
t:error("Get dc connect [<ip>=%s, <dctype>=%s] failed!",self:cfg_host(),self:cfg_ctype())
return false
end
return e[a](e,...)
end
function e:new_insert(...)
local e={...}
local e=self:new_model(unpack(e))
if(not e)then
t:warning('[orm base]:new_model return is empty!chk it!')
return false
end
self._model=e
t:dump(e,string.format('[%s]omr new insert',self:cfg_ctype()))
return self:_dc_runcmd('insert_data',self:cfg_tbname(),e)
end
function e:new_insert_with_tbname(a,...)
local e={...}
local e=self:new_model(unpack(e))
if(not e)then
t:warning('[orm base]:new_model return is empty!chk it!')
return false
end
self._model=e
t:dump(e,string.format('[%s]omr new insert',self:cfg_ctype()))
return self:_dc_runcmd('insert_data',a,e)
end
function e:update(t,e,...)
return self:_dc_runcmd('update',self:cfg_tbname(),t,e,...)
end
function e:update_with_tbname(a,e,t,...)
return self:_dc_runcmd('update',a,e,t,...)
end
function e:update_force(e,t)
local a=self:find(t)
if not a then
return self:new_insert(unpack(e))
end
return self:update(e,t)
end
function e:new_model()
end
function e:get_model()
return self._model
end
function e:find(e)
if(#self:cfg_tbname()==0)then
t:warning('[REDISINC]find_one params <kname> is empey!')
end
return self:_dc_runcmd('find_one',self:cfg_tbname(),e)
end
function e:find_all(e)
if(#self:cfg_tbname()==0)then
t:warning('[REDISINC]find_one params <kname> is empey!')
end
return self:_dc_runcmd('find_all',self:cfg_tbname(),e)
end
function e:find_all_with_tbname(e,t)
return self:_dc_runcmd('find_all',e,t)
end
function e:find_in_set_with_tbname(e,t,a)
return self:_dc_runcmd('find_in_set',e,t,a)
end
function e:find_in_set(e,t)
return self:_dc_runcmd('find_in_set',self:cfg_tbname(),e,t)
end
function e:find_in(t,e)
return self:_dc_runcmd('find_in',self:cfg_tbname(),t,e)
end
function e:get_limitcnt(e,t)
return self:_dc_runcmd('fetch_limitcnt',self:cfg_tbname(),e,t)
end
function e:get_limitcnt_with_tbname(t,e,a)
return self:_dc_runcmd('fetch_limitcnt',t,e,a)
end
function e:dele_one(e)
return self:_dc_runcmd('dele_one',self:cfg_tbname(),e)
end
function e:dele_one_with_tbname(t,e)
return self:_dc_runcmd('dele_one',t,e)
end
function e:_chk_dc_isredis()
local e=self._dccfg['ctype']=='redis'
if not e then
t:warning("the api is only in ctype='redis', other type funciton will do nothing!")
end
return e
end
function e:list_insert(e,t)
if not self:_chk_dc_isredis()then
return
end
return self:_dc_runcmd('list_insert',e,t)
end
function e:list_len(e)
if not self:_chk_dc_isredis()then
return
end
end
function e:list_pop(e)
if not self:_chk_dc_isredis()then
return
end
end
function e:list_push(e)
if not self:_chk_dc_isredis()then
return
end
end
function e:list_index(e,e)
if not self:_chk_dc_isredis()then
return
end
end
return e
end)
package.preload['framework.decorator.base_decorator']=(function(...)
local e=class("BaseDecorator")
local t=Ding
local a=ngx.req
local h=t.Logger
local n=require("cjson")
local i={
["DECODE_ERROR"]=1,
["PARAMS_ERROR"]=2,
["CONTENT_EMPTY"]=3
}
local r={
["DECODE_ERROR"]="json decode error",
["PARAMS_ERROR"]="params nec-keys not found",
["CONTENT_EMPTY"]="params contnet is empty"
}
local o={
"get_url_params_",
"get_body_params_",
"body_jsonparams_nec_",
"url_jsonparams_nec_"
}
function e:init_()
end
function e:bind(e)
self:init_()
t.setmethods(e,self,o)
self._s=e
end
function e:unbind(e)
t.unbind(e,o)
end
function e:get_url_params_()
local e=ngx.req.get_uri_args()or{}
return e
end
function e:get_body_params_()
a.read_body()
local a=a.get_body_data()
local o,e
t.Logger:info("Cont body-->>%s",a)
if not empty(a)then
try{
function()
e=n.decode(a)
end,
catch{
function(e)
h:error("json decode error!")
end
}
}
if not e then
o=1
end
end
return o,e
end
function e:body_jsonparams_nec_(s)
a.read_body()
local o=a.get_body_data()
local e,a
t.Logger:info("Cont body-->>%s",o)
if not empty(o)then
try{
function()
a=n.decode(o)
end,
catch{
function(e)
h:error("json decode error!")
end
}
}
if not a then
e="DECODE_ERROR"
else
if(type(s)=="table")then
for o,t in ipairs(s)do
if not(a[t])then
e="PARAMS_ERROR"
end
end
end
end
else
e="CONTENT_EMPTY"
end
if(e)then
self._s:doerror(i[e],r[e])
return false
else
return true,a
end
end
function e:url_jsonparams_nec_(o)
local a=ngx.req.get_uri_args()or{}
local e,n
t.Logger:dump(a,"Cont body-->>")
if(type(o)=="table")then
for o,t in ipairs(o)do
if not(a[t])then
e="PARAMS_ERROR"
end
end
end
if(e)then
self._s:doerror(i[e],r[e])
return false
else
return true,a
end
end
return e
end)
package.preload['framework.decorator.auth_decorator']=(function(...)
local e=class("AuthDecorator")
local t=Ding
local a=t.Logger
local i=t.Orm
local a={
["MISS_REQUIRE_AUTHHEADER"]=9001,
["GID_NOT_EXIST"]=9002,
["TOKEN_NOT_EXPIREIN"]=9003,
["SIGNATURE_COMP_MISSTAKE"]=9004,
}
local s={
[9001]="miss_require_authheader",
[9002]="gid_not_exist",
[9003]="token_not_expirein",
[9004]="signature_comp_misstake",
}
local o={
"X-D-GID",
"X-D-TOKEN",
"X-D-SIGNATURE"
}
local n={
"base_auth_"
}
function e:init_()
end
function e:bind(e,a,a)
self:init_()
t.setmethods(e,self,n)
self._s=e
end
function e:unbind(e)
t.unbind(e,n)
end
function e:_chk_require_header(e)
local t=e.get_headers()
local e=t[o[1]]
if e and tonumber(e)<=10 then
return true
end
for o,e in ipairs(o)do
if not t[e]then
return false,a["MISS_REQUIRE_AUTHHEADER"]
end
end
if not self:_chk_gid(e)then
return false,a["GID_NOT_EXIST"]
end
if not self:_chk_token(e)then
return false,a["TOKEN_NOT_EXPIREIN"]
end
if not self:_chk_signature()then
return false,SIGNATURE_COMP_MISSTAKE
end
return true,e
end
function e:base_auth_(e)
local t,e=self:_chk_require_header(e)
if not t then
self._s:doerror(e,s[e])
return false
end
return true,e
end
function e:_chk_gid(t)
local e=i:get("usr")
if not e then return false end
return e:find({gid=t})
end
function e:_chk_token(t)
local e=i:get("actusr")
if not e then return false end
return e:find({gid=t})
end
function e:_chk_signature()
return true
end
return e
end)
package.preload['framework.decorator.db_decorator']=(function(...)
local e=class("DBDecorator")
local t=ngx.shared.d
local a=ngx.req
local a=t.Logger
local o=require("cjson")
local o={
"is_ready_",
}
function e:init_()
end
function e:bind(e)
self:init_()
t.setmethods(e,self,o)
self._svr=e:svr()
end
function e:unbind(e)
t.unbind(e,o)
end
function e:is_ready_()
if not self._inc then
a:error("DB inc create failed!")
return false
end
if not self._iscon then
a:error("DB not connect yet!")
return false
end
return true
end
return _base end)
package.preload['framework.libs.jit_uuid']=(function(...)
local t=require"bit"
local e=t.tohex
local n=t.band
local i=t.bor
local t={
_VERSION="0.0.7"
}
function t.seed(e)
if not e then
if ngx then
e=ngx.time()+ngx.worker.pid()
elseif package.loaded["socket"]and package.loaded["socket"].gettime then
e=package.loaded["socket"].gettime()*1e4
else
e=os.time()
end
end
math.randomseed(e)
return e
end
do
if ngx and string.find(ngx.config.nginx_configure(),"--with-pcre-jit",nil,true)then
local o=type
local a=ngx.re.find
local i="^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"
function t.is_valid(e)
if o(e)~="string"or#e~=36 then
return false
end
return a(e,i,"ioj")~=nil
end
else
local o=string.match
local e="[0-9a-fA-F]"
local a=
"^"..
table.concat(
{
e:rep(8),
e:rep(4),
e:rep(4),
"[89ab]"..e:rep(3),
e:rep(12)
},
"%-"
)..
"$"
function t.is_valid(e)
if type(e)~="string"or#e~=36 then
return false
end
return o(e,a)~=nil
end
end
end
do
local o=string.format
local a=math.random
function t.generate_v4()
return(o(
"%s%s%s%s-%s%s-%s%s-%s%s-%s%s%s%s%s%s",
e(a(0,255),2),
e(a(0,255),2),
e(a(0,255),2),
e(a(0,255),2),
e(a(0,255),2),
e(a(0,255),2),
e(i(n(a(0,255),15),64),2),
e(a(0,255),2),
e(i(n(a(0,255),63),128),2),
e(a(0,255),2),
e(a(0,255),2),
e(a(0,255),2),
e(a(0,255),2),
e(a(0,255),2),
e(a(0,255),2),
e(a(0,255),2)
))
end
end
do
if ngx then
local o=require"ffi"
local r=tonumber
local j=assert
local g=error
local y=table.concat
local v=type
local b=string.char
local w=string.format
local a=string.sub
local p=ngx.re.gmatch
local f=ngx.sha1_bin
local l=ngx.md5
local h=o.C
local d=o.new
local u=o.string
local c=o.cast
local s
do
local e
e,s=pcall(require,"table.new")
if not e then
s=function(e,e)
return{}
end
end
end
o.cdef[[
            typedef unsigned char u_char;
            typedef intptr_t ngx_int_t;

            u_char * ngx_hex_dump(u_char *dst, const u_char *src, size_t len);
            ngx_int_t ngx_hextoi(u_char *line, size_t n);
        ]]
local m=o.typeof("uint8_t[?]")
local k=o.typeof("u_char *")
local function q(t)
local e=#t
local a=e*2
local o=d(m,a)
h.ngx_hex_dump(o,t,e)
return u(o,a)
end
local function o(e)
local t=c(k,e)
local e=r(h.ngx_hextoi(t,#e))
if e==-1 then
g("could not convert hex to number")
end
return e
end
local h=s(16,0)
local function s(o,i)
if not t.is_valid(o)then
return nil,"namespace must be a valid UUID"
end
local e=0
local t,o=p(o,[[([\da-f][\da-f])]])
if not t then
return nil,"could not create iter: "..o
end
while true do
local a,t=t()
if t then
return nil,t
end
if not a then
break
end
e=e+1
h[e]=b(r(a[0],16))
end
j(e==16,"invalid binary namespace buffer length")
local t=y(h)
return function(e)
if v(e)~="string"then
return nil,"name must be a string"
end
local e,t,o=i(t,e)
return(w(
"%s-%s-%s%s-%s%s-%s",
a(e,1,8),
a(e,9,12),
t,
a(e,15,16),
o,
a(e,19,20),
a(e,21,32)
))
end
end
local function r(s,t)
local t=l(s..t)
return t,e(i(n(o(a(t,13,14)),15),48),2),e(
i(n(o(a(t,17,18)),63),128),
2
)
end
local function h(t,s)
local t=q(f(t..s))
return t,e(i(n(o(a(t,13,14)),15),80),2),e(
i(n(o(a(t,17,18)),63),128),
2
)
end
function t.factory_v3(e)
return s(e,r)
end
function t.factory_v5(e)
return s(e,h)
end
function t.generate_v3(e,a)
local e,t=t.factory_v3(e)
if not e then
return nil,t
end
return e(a)
end
function t.generate_v5(e,a)
local e,t=t.factory_v5(e)
if not e then
return nil,t
end
return e(a)
end
else
function t.factory_v3()
error("v3 UUID generation only supported in ngx_lua",2)
end
function t.generate_v3()
error("v3 UUID generation only supported in ngx_lua",2)
end
function t.factory_v5()
error("v5 UUID generation only supported in ngx_lua",2)
end
function t.generate_v5()
error("v5 UUID generation only supported in ngx_lua",2)
end
end
end
return setmetatable(
t,
{
__call=t.generate_v4
}
)
end)
package.preload['framework.libs.msgpack']=(function(...)
local t,e=pcall(require,'jit')
if not t then
e=nil
end
local f=string.pack and#string.pack('n',0)or 8
local w=math.type and(math.type(0)==math.type(0))or false
if not e and _VERSION<'Lua 5.3'then
local e=loadstring or load
local e=string.dump(e"a = 1")
local e={e:sub(1,12):byte(1,12)}
f=e[11]
w=1==e[12]
end
local g=assert
local n=error
local u=pairs
local k=pcall
local c=setmetatable
local r=tostring
local s=type
local a=require'string'.char
local e=require'math'.floor
local v=require'math'.tointeger or e
local m=require'math'.frexp or require'mathx'.frexp
local l=require'math'.ldexp or require'mathx'.ldexp
local d=require'math'.huge
local q=require'table'.concat
local t=nil
local i={}
local function h(t,e,a)
n("bad argument #"..r(e).." to "
..t.." ("..a..")")
end
local function y(a,o,t,e)
h(a,o,e.." expected, got "..s(t))
end
local function j(a,o,e,t)
if s(e)~=t then
y(a,o,e,t)
end
end
local t=c({},{
__index=function(t,e)n("pack '"..e.."' is unimplemented")end
})
i.packers=t
t['nil']=function(e)
e[#e+1]=a(192)
end
t['boolean']=function(e,o)
if o then
e[#e+1]=a(195)
else
e[#e+1]=a(194)
end
end
t['string_compat']=function(i,s)
local o=#s
if o<=31 then
i[#i+1]=a(160+o)
elseif o<=65535 then
i[#i+1]=a(218,
e(o/256),
o%256)
elseif o<=4294967295 then
i[#i+1]=a(219,
e(o/16777216),
e(o/65536)%256,
e(o/256)%256,
o%256)
else
n"overflow in pack 'string_compat'"
end
i[#i+1]=s
end
t['_string']=function(i,s)
local o=#s
if o<=31 then
i[#i+1]=a(160+o)
elseif o<=255 then
i[#i+1]=a(217,
o)
elseif o<=65535 then
i[#i+1]=a(218,
e(o/256),
o%256)
elseif o<=4294967295 then
i[#i+1]=a(219,
e(o/16777216),
e(o/65536)%256,
e(o/256)%256,
o%256)
else
n"overflow in pack 'string'"
end
i[#i+1]=s
end
t['binary']=function(o,i)
local t=#i
if t<=255 then
o[#o+1]=a(196,
t)
elseif t<=65535 then
o[#o+1]=a(197,
e(t/256),
t%256)
elseif t<=4294967295 then
o[#o+1]=a(198,
e(t/16777216),
e(t/65536)%256,
e(t/256)%256,
t%256)
else
n"overflow in pack 'binary'"
end
o[#o+1]=i
end
local b=function(e)
if e=='string_compat'then
t['string']=t['string_compat']
elseif e=='string'then
t['string']=t['_string']
elseif e=='binary'then
t['string']=t['binary']
else
h('set_string',1,"invalid option '"..e.."'")
end
end
i.set_string=b
t['map']=function(i,h,o)
if o<=15 then
i[#i+1]=a(128+o)
elseif o<=65535 then
i[#i+1]=a(222,
e(o/256),
o%256)
elseif o<=4294967295 then
i[#i+1]=a(223,
e(o/16777216),
e(o/65536)%256,
e(o/256)%256,
o%256)
else
n"overflow in pack 'map'"
end
for a,e in u(h)do
t[s(a)](i,a)
t[s(e)](i,e)
end
end
t['array']=function(i,h,o)
if o<=15 then
i[#i+1]=a(144+o)
elseif o<=65535 then
i[#i+1]=a(220,
e(o/256),
o%256)
elseif o<=4294967295 then
i[#i+1]=a(221,
e(o/16777216),
e(o/65536)%256,
e(o/256)%256,
o%256)
else
n"overflow in pack 'array'"
end
for e=1,o do
local e=h[e]
t[s(e)](i,e)
end
end
local y=function(a)
if a=='without_hole'then
t['_table']=function(n,a)
local o,e,i=false,0,0
for t in u(a)do
if s(t)=='number'and t>0 then
if t>i then
i=t
end
else
o=true
end
e=e+1
end
if i~=e then
o=true
end
if o then
return t['map'](n,a,e)
else
return t['array'](n,a,e)
end
end
elseif a=='with_hole'then
t['_table']=function(n,i)
local h,o,a=false,0,0
for e in u(i)do
if s(e)=='number'and e>0 then
if e>a then
a=e
end
else
h=true
end
o=o+1
end
if h then
return t['map'](n,i,o)
else
return t['array'](n,i,a)
end
end
elseif a=='always_as_map'then
t['_table']=function(o,a)
local e=0
for t in u(a)do
e=e+1
end
return t['map'](o,a,e)
end
else
h('set_array',1,"invalid option '"..a.."'")
end
end
i.set_array=y
t['table']=function(e,a)
return t['_table'](e,a)
end
t['unsigned']=function(i,o)
if o>=0 then
if o<=127 then
i[#i+1]=a(o)
elseif o<=255 then
i[#i+1]=a(204,
o)
elseif o<=65535 then
i[#i+1]=a(205,
e(o/256),
o%256)
elseif o<=4294967295 then
i[#i+1]=a(206,
e(o/16777216),
e(o/65536)%256,
e(o/256)%256,
o%256)
else
i[#i+1]=a(207,
0,
e(o/0x1000000000000)%256,
e(o/1099511627776)%256,
e(o/4294967296)%256,
e(o/16777216)%256,
e(o/65536)%256,
e(o/256)%256,
o%256)
end
else
if o>=-32 then
i[#i+1]=a(256+o)
elseif o>=-128 then
i[#i+1]=a(208,
256+o)
elseif o>=-32768 then
o=65536+o
i[#i+1]=a(209,
e(o/256),
o%256)
elseif o>=-2147483648 then
o=4294967296+o
i[#i+1]=a(210,
e(o/16777216),
e(o/65536)%256,
e(o/256)%256,
o%256)
else
i[#i+1]=a(211,
255,
e(o/0x1000000000000)%256,
e(o/1099511627776)%256,
e(o/4294967296)%256,
e(o/16777216)%256,
e(o/65536)%256,
e(o/256)%256,
o%256)
end
end
end
t['signed']=function(o,t)
if t>=0 then
if t<=127 then
o[#o+1]=a(t)
elseif t<=32767 then
o[#o+1]=a(209,
e(t/256),
t%256)
elseif t<=2147483647 then
o[#o+1]=a(210,
e(t/16777216),
e(t/65536)%256,
e(t/256)%256,
t%256)
else
o[#o+1]=a(211,
0,
e(t/0x1000000000000)%256,
e(t/1099511627776)%256,
e(t/4294967296)%256,
e(t/16777216)%256,
e(t/65536)%256,
e(t/256)%256,
t%256)
end
else
if t>=-32 then
o[#o+1]=a(224+32+t)
elseif t>=-128 then
o[#o+1]=a(208,
256+t)
elseif t>=-32768 then
t=65536+t
o[#o+1]=a(209,
e(t/256),
t%256)
elseif t>=-2147483648 then
t=4294967296+t
o[#o+1]=a(210,
e(t/16777216),
e(t/65536)%256,
e(t/256)%256,
t%256)
else
o[#o+1]=a(211,
255,
e(t/0x1000000000000)%256,
e(t/1099511627776)%256,
e(t/4294967296)%256,
e(t/16777216)%256,
e(t/65536)%256,
e(t/256)%256,
t%256)
end
end
end
local p=function(e)
if e=='unsigned'then
t['integer']=t['unsigned']
elseif e=='signed'then
t['integer']=t['signed']
else
h('set_integer',1,"invalid option '"..e.."'")
end
end
i.set_integer=p
t['float']=function(o,i)
local s=0
if i<0 then
s=128
i=-i
end
local i,n=m(i)
if i~=i then
o[#o+1]=a(202,
255,136,0,0)
elseif i==d or n>128 then
if s==0 then
o[#o+1]=a(202,
127,128,0,0)
else
o[#o+1]=a(202,
255,128,0,0)
end
elseif(i==0 and n==0)or n<-126 then
o[#o+1]=a(202,
s,0,0,0)
else
n=n+126
i=(i*2-1)*l(.5,24)
o[#o+1]=a(202,
s+e(n/2),
(n%2)*128+e(i/65536),
e(i/256)%256,
i%256)
end
end
t['double']=function(o,t)
local n=0
if t<0 then
n=128
t=-t
end
local t,i=m(t)
if t~=t then
o[#o+1]=a(203,
255,248,0,0,0,0,0,0)
elseif t==d or i>1024 then
if n==0 then
o[#o+1]=a(203,
127,240,0,0,0,0,0,0)
else
o[#o+1]=a(203,
255,240,0,0,0,0,0,0)
end
elseif(t==0 and i==0)or i<-1022 then
o[#o+1]=a(203,
n,0,0,0,0,0,0,0)
else
i=i+1022
t=(t*2-1)*l(.5,53)
o[#o+1]=a(203,
n+e(i/16),
(i%16)*16+e(t/0x1000000000000),
e(t/1099511627776)%256,
e(t/4294967296)%256,
e(t/16777216)%256,
e(t/65536)%256,
e(t/256)%256,
t%256)
end
end
local u=function(o)
if o=='integer'then
t['number']=t['signed']
elseif o=='float'then
t['number']=function(o,a)
if e(a)~=a or a~=a or a>340282347e30 or a<-340282347e30 then
return t['float'](o,a)
else
return t['integer'](o,a)
end
end
elseif o=='double'then
t['number']=function(o,a)
if e(a)~=a or a~=a or a>17976931348623e295 or a<-17976931348623e295 then
return t['double'](o,a)
else
return t['integer'](o,a)
end
end
else
h('set_number',1,"invalid option '"..o.."'")
end
end
i.set_number=u
for e=0,4 do
local o=v(2^e)
local n=212+e
t['fixext'..r(o)]=function(e,t,i)
g(#i==o,"bad length for fixext"..r(o))
e[#e+1]=a(n,
t<0 and t+256 or t)
e[#e+1]=i
end
end
t['ext']=function(i,o,s)
local t=#s
if t<=255 then
i[#i+1]=a(199,
t,
o<0 and o+256 or o)
elseif t<=65535 then
i[#i+1]=a(200,
e(t/256),
t%256,
o<0 and o+256 or o)
elseif t<=4294967295 then
i[#i+1]=a(201,
e(t/16777216),
e(t/65536)%256,
e(t/256)%256,
t%256,
o<0 and o+256 or o)
else
n"overflow in pack 'ext'"
end
i[#i+1]=s
end
function i.pack(e)
local a={}
t[s(e)](a,e)
return q(a)
end
local g=c({
[192]='nil',
[194]='false',
[195]='true',
[196]='bin8',
[197]='bin16',
[198]='bin32',
[199]='ext8',
[200]='ext16',
[201]='ext32',
[202]='float',
[203]='double',
[204]='uint8',
[205]='uint16',
[206]='uint32',
[207]='uint64',
[208]='int8',
[209]='int16',
[210]='int32',
[211]='int64',
[212]='fixext1',
[213]='fixext2',
[214]='fixext4',
[215]='fixext8',
[216]='fixext16',
[217]='str8',
[218]='str16',
[219]='str32',
[220]='array16',
[221]='array32',
[222]='map16',
[223]='map32',
},{__index=function(t,e)
if e<192 then
if e<128 then
return'fixnum_pos'
elseif e<144 then
return'fixmap'
elseif e<160 then
return'fixarray'
else
return'fixstr'
end
elseif e>223 then
return'fixnum_neg'
else
return'reserved'..r(e)
end
end})
i.types_map=g
local a=c({},{
__index=function(t,e)n("unpack '"..e.."' is unimplemented")end
})
i.unpackers=a
local function m(t,o)
local e={}
local a=a['any']
for o=1,o do
e[o]=a(t)
end
return e
end
local function c(n,e)
local o={}
local t=a['any']
for e=1,e do
local e=t(n)
local t=t(n)
if e==nil then
e=i.sentinel
end
if e~=nil then
o[e]=t
end
end
return o
end
a['any']=function(e)
local i,t,o=e.s,e.i,e.j
if t>o then
e:underflow(t)
i,t,o=e.s,e.i,e.j
end
local o=i:sub(t,t):byte()
e.i=t+1
return a[g[o]](e,o)
end
a['nil']=function()
return nil
end
a['false']=function()
return false
end
a['true']=function()
return true
end
a['float']=function(t)
local o,i,n=t.s,t.i,t.j
if i+3>n then
t:underflow(i+3)
o,i,n=t.s,t.i,t.j
end
local s,n,h,r=o:sub(i,i+3):byte(1,4)
local o=s>127
local s=(s%128)*2+e(n/128)
local n=((n%128)*256+h)*256+r
if o then
o=-1
else
o=1
end
local e
if n==0 and s==0 then
e=o*0
elseif s==255 then
if n==0 then
e=o*d
else
e=0/0
end
else
e=o*l(1+n/8388608,s-127)
end
t.i=i+4
return e
end
a['double']=function(t)
local n,o,i=t.s,t.i,t.j
if o+7>i then
t:underflow(o+7)
n,o,i=t.s,t.i,t.j
end
local n,s,f,c,m,u,r,h=n:sub(o,o+7):byte(1,8)
local i=n>127
local n=(n%128)*16+e(s/16)
local s=((((((s%16)*256+f)*256+c)*256+m)*256+u)*256+r)*256+h
if i then
i=-1
else
i=1
end
local e
if s==0 and n==0 then
e=i*0
elseif n==2047 then
if s==0 then
e=i*d
else
e=0/0
end
else
e=i*l(1+s/4503599627370496,n-1023)
end
t.i=o+8
return e
end
a['fixnum_pos']=function(t,e)
return e
end
a['uint8']=function(e)
local o,t,i=e.s,e.i,e.j
if t>i then
e:underflow(t)
o,t,i=e.s,e.i,e.j
end
local o=o:sub(t,t):byte()
e.i=t+1
return o
end
a['uint16']=function(e)
local i,t,o=e.s,e.i,e.j
if t+1>o then
e:underflow(t+1)
i,t,o=e.s,e.i,e.j
end
local o,i=i:sub(t,t+1):byte(1,2)
e.i=t+2
return o*256+i
end
a['uint32']=function(e)
local i,t,o=e.s,e.i,e.j
if t+3>o then
e:underflow(t+3)
i,t,o=e.s,e.i,e.j
end
local o,n,i,s=i:sub(t,t+3):byte(1,4)
e.i=t+4
return((o*256+n)*256+i)*256+s
end
a['uint64']=function(e)
local i,t,o=e.s,e.i,e.j
if t+7>o then
e:underflow(t+7)
i,t,o=e.s,e.i,e.j
end
local i,o,l,d,s,n,h,r=i:sub(t,t+7):byte(1,8)
e.i=t+8
return((((((i*256+o)*256+l)*256+d)*256+s)*256+n)*256+h)*256+r
end
a['fixnum_neg']=function(t,e)
return e-256
end
a['int8']=function(e)
local o,t,i=e.s,e.i,e.j
if t>i then
e:underflow(t)
o,t,i=e.s,e.i,e.j
end
local o=o:sub(t,t):byte()
e.i=t+1
if o<128 then
return o
else
return o-256
end
end
a['int16']=function(e)
local o,t,i=e.s,e.i,e.j
if t+1>i then
e:underflow(t+1)
o,t,i=e.s,e.i,e.j
end
local o,i=o:sub(t,t+1):byte(1,2)
e.i=t+2
if o<128 then
return o*256+i
else
return((o-255)*256+(i-255))-1
end
end
a['int32']=function(e)
local i,t,o=e.s,e.i,e.j
if t+3>o then
e:underflow(t+3)
i,t,o=e.s,e.i,e.j
end
local o,i,n,s=i:sub(t,t+3):byte(1,4)
e.i=t+4
if o<128 then
return((o*256+i)*256+n)*256+s
else
return((((o-255)*256+(i-255))*256+(n-255))*256+(s-255))-1
end
end
a['int64']=function(e)
local o,t,i=e.s,e.i,e.j
if t+7>i then
e:underflow(t+7)
o,t,i=e.s,e.i,e.j
end
local o,d,l,r,s,h,i,n=o:sub(t,t+7):byte(1,8)
e.i=t+8
if o<128 then
return((((((o*256+d)*256+l)*256+r)*256+s)*256+h)*256+i)*256+n
else
return((((((((o-255)*256+(d-255))*256+(l-255))*256+(r-255))*256+(s-255))*256+(h-255))*256+(i-255))*256+(n-255))-1
end
end
a['fixstr']=function(e,o)
local n,t,s=e.s,e.i,e.j
local i=o%32
local o=t+i-1
if o>s then
e:underflow(o)
n,t,s=e.s,e.i,e.j
o=t+i-1
end
e.i=t+i
return n:sub(t,o)
end
a['str8']=function(e)
local n,t,o=e.s,e.i,e.j
if t>o then
e:underflow(t)
n,t,o=e.s,e.i,e.j
end
local s=n:sub(t,t):byte()
t=t+1
e.i=t
local i=t+s-1
if i>o then
e:underflow(i)
n,t,o=e.s,e.i,e.j
i=t+s-1
end
e.i=t+s
return n:sub(t,i)
end
a['str16']=function(t)
local i,e,n=t.s,t.i,t.j
if e+1>n then
t:underflow(e+1)
i,e,n=t.s,t.i,t.j
end
local o,s=i:sub(e,e+1):byte(1,2)
e=e+2
t.i=e
local s=o*256+s
local o=e+s-1
if o>n then
t:underflow(o)
i,e,n=t.s,t.i,t.j
o=e+s-1
end
t.i=e+s
return i:sub(e,o)
end
a['str32']=function(e)
local n,t,i=e.s,e.i,e.j
if t+3>i then
e:underflow(t+3)
n,t,i=e.s,e.i,e.j
end
local r,h,s,o=n:sub(t,t+3):byte(1,4)
t=t+4
e.i=t
local s=((r*256+h)*256+s)*256+o
local o=t+s-1
if o>i then
e:underflow(o)
n,t,i=e.s,e.i,e.j
o=t+s-1
end
e.i=t+s
return n:sub(t,o)
end
a['bin8']=a['str8']
a['bin16']=a['str16']
a['bin32']=a['str32']
a['fixarray']=function(t,e)
return m(t,e%16)
end
a['array16']=function(e)
local o,t,i=e.s,e.i,e.j
if t+1>i then
e:underflow(t+1)
o,t,i=e.s,e.i,e.j
end
local i,o=o:sub(t,t+1):byte(1,2)
e.i=t+2
return m(e,i*256+o)
end
a['array32']=function(e)
local i,t,o=e.s,e.i,e.j
if t+3>o then
e:underflow(t+3)
i,t,o=e.s,e.i,e.j
end
local i,n,o,s=i:sub(t,t+3):byte(1,4)
e.i=t+4
return m(e,((i*256+n)*256+o)*256+s)
end
a['fixmap']=function(t,e)
return c(t,e%16)
end
a['map16']=function(e)
local i,t,o=e.s,e.i,e.j
if t+1>o then
e:underflow(t+1)
i,t,o=e.s,e.i,e.j
end
local i,o=i:sub(t,t+1):byte(1,2)
e.i=t+2
return c(e,i*256+o)
end
a['map32']=function(e)
local a,t,o=e.s,e.i,e.j
if t+3>o then
e:underflow(t+3)
a,t,o=e.s,e.i,e.j
end
local n,o,i,a=a:sub(t,t+3):byte(1,4)
e.i=t+4
return c(e,((n*256+o)*256+i)*256+a)
end
function i.build_ext(e,e)
return nil
end
for e=0,4 do
local n=v(2^e)
a['fixext'..r(n)]=function(t)
local s,e,o=t.s,t.i,t.j
if e>o then
t:underflow(e)
s,e,o=t.s,t.i,t.j
end
local h=s:sub(e,e):byte()
e=e+1
t.i=e
local a=e+n-1
if a>o then
t:underflow(a)
s,e,o=t.s,t.i,t.j
a=e+n-1
end
t.i=e+n
return i.build_ext(h<128 and h or h-256,s:sub(e,a))
end
end
a['ext8']=function(t)
local n,e,o=t.s,t.i,t.j
if e>o then
t:underflow(e)
n,e,o=t.s,t.i,t.j
end
local r=n:sub(e,e):byte()
e=e+1
t.i=e
if e>o then
t:underflow(e)
n,e,o=t.s,t.i,t.j
end
local h=n:sub(e,e):byte()
e=e+1
t.i=e
local s=e+r-1
if s>o then
t:underflow(s)
n,e,o=t.s,t.i,t.j
s=e+r-1
end
t.i=e+r
return i.build_ext(h<128 and h or h-256,n:sub(e,s))
end
a['ext16']=function(t)
local o,e,n=t.s,t.i,t.j
if e+1>n then
t:underflow(e+1)
o,e,n=t.s,t.i,t.j
end
local s,h=o:sub(e,e+1):byte(1,2)
e=e+2
t.i=e
local r=s*256+h
if e>n then
t:underflow(e)
o,e,n=t.s,t.i,t.j
end
local h=o:sub(e,e):byte()
e=e+1
t.i=e
local s=e+r-1
if s>n then
t:underflow(s)
o,e,n=t.s,t.i,t.j
s=e+r-1
end
t.i=e+r
return i.build_ext(h<128 and h or h-256,o:sub(e,s))
end
a['ext32']=function(t)
local o,e,a=t.s,t.i,t.j
if e+3>a then
t:underflow(e+3)
o,e,a=t.s,t.i,t.j
end
local r,h,s,n=o:sub(e,e+3):byte(1,4)
e=e+4
t.i=e
local s=((r*256+h)*256+s)*256+n
if e>a then
t:underflow(e)
o,e,a=t.s,t.i,t.j
end
local h=o:sub(e,e):byte()
e=e+1
t.i=e
local n=e+s-1
if n>a then
t:underflow(n)
o,e,a=t.s,t.i,t.j
n=e+s-1
end
t.i=e+s
return i.build_ext(h<128 and h or h-256,o:sub(e,n))
end
local function o(e)
return{
s=e,
i=1,
j=#e,
underflow=function(e)
n"missing bytes"
end,
}
end
local function r(a)
return{
s='',
i=1,
j=0,
underflow=function(e,t)
e.s=e.s:sub(e.i)
t=t-e.i+1
e.i=1
e.j=0
while t>e.j do
local t=a()
if not t then
n"missing bytes"
end
e.s=e.s..t
e.j=#e.s
end
end,
}
end
function i.unpack(e)
j('unpack',1,e,'string')
local e=o(e)
local t=a['any'](e)
if e.i<e.j then
n"extra bytes"
end
return t
end
function i.unpacker(t)
if s(t)=='string'then
local e=o(t)
return function()
if e.i<=e.j then
return e.i,a['any'](e)
end
end
elseif s(t)=='function'then
local e=r(t)
return function()
if e.i>e.j then
k(e.underflow,e,e.i)
end
if e.i<=e.j then
return true,a['any'](e)
end
end
else
h('unpacker',1,"string or function expected, got "..s(t))
end
end
b'string_compat'
p'unsigned'
if w then
t['double']=t['integer']
t['float']=t['integer']
u'integer'
elseif f==4 then
t['double']=t['float']
i.small_lua=true
u'float'
else
u'double'
if f>8 then
i.long_double=true
end
end
y'without_hole'
i._VERSION='0.3.3'
i._DESCRIPTION="lua-MessagePack : a pure Lua implementation"
i._COPYRIGHT="Copyright (c) 2012-2016 Francois Perrad"
return i
end)
package.preload['framework.log.logger']=(function(...)
local e=class('Logger')
e.CRITICAL=50
e.ERROR=40
e.WARNING=30
e.INFO=20
e.DEBUG=10
e.NOTSET=0
function e:ctor(t,...)
self:setLevel(t or e.NOTSET)
self._handlers={...}
end
function e:setLevel(e)
self._level=e
end
function e:getLevel(e)
return self._level
end
function e:addHandler(e)
self._handlers[#self._handlers+1]=e
end
function e:clearHandler()
self._handlers={}
end
function e:flush()
for t,e in pairs(self._handlers)do
e:flush()
end
end
function e:log(e,t,...)
if e<self._level then return end
local o={...}
for i,a in pairs(self._handlers)do
a:emit(e,t,o)
end
end
function e:debug(t,...)
self:log(e.DEBUG,t,...)
end
function e:info(t,...)
self:log(e.INFO,t,...)
end
function e:warning(t,...)
self:log(e.WARNING,t,...)
end
function e:error(t,...)
self:log(e.ERROR,t,...)
end
function e:critical(t,...)
self:log(e.CRITICAL,t,...)
end
function e:dump(a,o,t,i)
t=t or e.DEBUG
if t<self._level then return end
for n,e in pairs(self._handlers)do
e:dumpemit(t,a,o,i)
end
end
return e
end)
package.preload['framework.log.loghandler']=(function(...)
local e=class('LogHandler')
e.TABLE_DPSTEP=5
e.LOGNAME={
[10]="DEBUG",
[20]="INFO",
[30]="WARNING",
[40]="ERROR",
[50]="CRITICAL",
}
local function i(e)
return type(e)=='string'and string.find(e,"%%")
end
local function t(e)
if type(e)=="string"then
e="\""..e.."\""
end
return tostring(e)
end
function e:ctor(e,t)
self._gettime=nil
self._starttime=nil
if e then
self._gettime=t or os.time
self._starttime=(e==0 and self._gettime())or e
end
self._basefmt="[dlog]"
end
function e:emit(e,e,e)
end
function e:dumpemit(e,e,e,e)
end
function e:flush()
end
function e:getString(o,t,a)
local e=""
if self._starttime then
e=string.format('[%.4f]',self._gettime()-self._starttime)..e
end
if(#a>0)then
if i(t)then
e=string.format(t,unpack(a))
else
e=e..t
for t in ipairs(a)do
e=e..tostring(t)
end
end
else
e=e..tostring(t)
end
return self:getFmtStr(o,e)
end
function e:setFmt(e)
self._basefmt=e
end
function e:getFmtStr(e,a)
local t=self.LOGNAME[e]
local e="%s-%s-%s: %s\n"
return string.format(e,self._basefmt,t,ngx.now(),a)
end
function e:getTBString(m,c,u,s)
if type(s)~="number"then s=e.TABLE_DPSTEP end
local l={}
local e={}
local a=string.split(debug.traceback("",2),"\n")
local function d(i,a,o,r,h)
a=a or"var"
local n=""
if type(h)=="number"then
n=string.rep(" ",h-string.len(t(a)))
end
if type(i)~="table"then
e[#e+1]=string.format("%s%s%s = %s",o,t(a),n,t(i))
elseif l[tostring(i)]then
e[#e+1]=string.format("%s%s%s = *REF*",o,t(a),n)
else
l[tostring(i)]=true
if r>s then
e[#e+1]=string.format("%s%s = *MAX NESTING*",o,t(a))
else
e[#e+1]=string.format("%s%s = {",o,t(a))
local h=o.."    "
local a={}
local n=0
local s={}
for e,o in pairs(i)do
a[#a+1]=e
local t=t(e)
local t=string.len(t)
if t>n then n=t end
s[e]=o
end
table.sort(a,function(t,e)
if type(t)=="number"and type(e)=="number"then
return t<e
else
return tostring(t)<tostring(e)
end
end)
for a,t in ipairs(a)do
d(s[t],t,h,r+1,n)
end
e[#e+1]=string.format("%s}",o)
end
end
end
d(c,u,"- ",1)
local t=""
for a,e in ipairs(e)do
t=t..e.."\n"
end
return self:getFmtStr(m,t)
end
return e
end)
package.preload['framework.log.printhandler']=(function(...)
local e=class('PrintHandler',import(".loghandler"))
function e:ctor(a,o,t)
e.super.ctor(self,o,t)
self._printfun=a or print
end
function e:emit(a,t,e)
local e=self:getString(a,t,e)
e=e.."\n"
self._printfun(e)
end
function e:dumpemit(t,a,i,o)
local t=self:getTBString(t,a,i,o)
self._printfun(t)
end
e.printHandler=e.new()
return e
end)
package.preload['framework.log.sysloghandler']=(function(...)
local t=class('SyslogHandler',import('.LogHandler'))
import('..utils.bit')
local e=import('.Logger')
local a=514
local a=514
local n=0
local m=1
local i=2
local a=3
local o=4
local c=5
local u=6
local r=7
local h=0
local d=1
local l=2
local f=3
local s=4
local k=5
local w=6
local z=7
local x=8
local E=9
local A=10
local T=11
local j=16
local _=17
local q=18
local v=19
local p=20
local y=21
local b=22
local g=23
local r={
["alert"]=m,
["crit"]=i,
["critical"]=i,
["debug"]=r,
["emerg"]=n,
["err"]=a,
["error"]=a,
["info"]=u,
["notice"]=c,
["panic"]=n,
["warn"]=o,
["warning"]=o,
}
local s={
["auth"]=s,
["authpriv"]=A,
["cron"]=E,
["daemon"]=f,
["ftp"]=T,
["kern"]=h,
["lpr"]=w,
["mail"]=l,
["news"]=z,
["security"]=s,
["syslog"]=k,
["user"]=d,
["uucp"]=x,
["local0"]=j,
["local1"]=_,
["local2"]=q,
["local3"]=v,
["local4"]=p,
["local5"]=y,
["local6"]=b,
["local7"]=g,
}
local h={
[e.CRITICAL]='critical',
[e.ERROR]='error',
[e.WARNING]='warning',
[e.INFO]='info',
[e.DEBUG]='debug',
}
local n={
'<%d>1',
'%Y-%m-%dT%H:%M:%S.000000+08:00',
'HOSTNAME',
'team1201',
'APP-NAME',
'9999',
'-',
'-',
}
function t:ctor(e,a,i,o)
t.super.ctor(self)
self._ada=e
self.facility=a
self._appname=i or'NO-APP-NAME'
self._autoflush=o
end
function t:encodePriority(t,e)
if type(t)=='string'then
t=s[t]
end
if type(e)=='string'then
e=r[e]
end
return bit.bor(bit.lshift(t,3),e)
end
function t:mapPriority(e)
return h[e]or'warning'
end
function t:emit(a,t,e)
str=self:getString(a,t,e)
local t,e=self._ada:log(str)
if e then
print("failed to log message: ",e)
return
end
if self._autoflush then
self:flush()
end
end
function t:getString(o,a,t)
local e=clone(n)
e[1]=string.format(e[1],
self:encodePriority(self.facility,self:mapPriority(o)))
e[2]=os.date(e[2])
e[4]=self._appname
if#t>0 and
type(a)=='string'and
string.find(a,"%%")then
e[#e+1]=string.format(a,unpack(t))
else
e[#e+1]=a
for a=1,#t do
e[#e+1]=tostring(t[a])
end
end
e[#e+1]='\n'
return table.concat(e,' ')
end
function t:flush()
self._ada:flush()
end
return t
end)
package.preload['framework.log.filehandler']=(function(...)
local e=class('LogHandler',import(".loghandler"))
function e:ctor(a,t,o,i,n)
e.super.ctor(self,i,n)
t=t or'w+b'
if type(a)=='string'then
self.filename=filename
self._file=io.open(a,t)
else
self._file=a
end
self._autoflush=o
end
function e:emit(e,a,t)
str=self:getString(e,a,t)
self._file:write(str..'\n')
if self._autoflush then
self:flush()
end
end
function e:flush()
self._file:flush()
end
function e:dumpemit(e,t,a)
local e=self:getTBString(e,t,a)
self._file:write(e.."\n")
if self._autoflush then
self:flush()
end
end
return e
end)
package.preload['framework.log.init']=(function(...)
local e={}
e.Logger=import(".logger")
e.LogHandler=import(".loghandler")
e.PrintHandler=import(".printhandler")
e.FileHandler=import(".filehandler")
return e
end)
package.preload['framework.utils.utildecode']=(function(...)
local e={}
local function t(e)
require("framework.json")
return json.decode(e)
end
function e.decode(e)
return t(e)
end
return e
end)
package.preload['framework.utils.utilfs']=(function(...)
local e={}
local t=require("fs")
function e.is_fileexit()
end
return e end)
package.preload['framework.utils.utilrds']=(function(...)
local e={}
local t=Ding
local n=t.Logger
local c=[[
INSERT INTO {tbname} ({defienks}) VALUES ({vals})
]]
local u=[[
SELECT * FROM `{tbname}` WHERE {condition}
]]
local m=[[
SELECT * FROM ({tbname}) LIMIT {starnum},{endnum}
]]
local w=[[
SELECT * FROM {tbname} WHERE FIND_IN_SET('{condkey}', '{condlist}');     
]]
local f=[[
SELECT * FROM {tbname} WHERE {condkey} IN ({condlist});     
]]
local d=[[
SELECT * FROM {tbname} GROUP BY {condlist};
]]
local l=[[
DELETE FROM {tbname} WHERE {condition}
]]
local r=[[
UPDATE {tbname} SET {vallist} WHERE ({condition})
]]
local function a(t,n)
local a=''
local o
local e=1
local h=table.nums(t)
local i=''
for s,t in pairs(t)do
i=e~=h and' AND 'or''
o=type(t)=='string'and string.format(not n and"'%s'"or'%s',t)or t
a=a..string.format('%s=%s',s,o)..i
e=e+1
end
return a
end
local function t(a)
local o=#a
local e=''
local t
for i,a in ipairs(a)do
t=i==o and''or', '
e=e..tostring(a)..t
end
return e
end
local function s(a)
local e=''
local o
local t=1
local s=table.nums(a)
local i=''
for n,a in pairs(a)do
i=t~=s and', 'or''
o=tostring(a)
e=e..string.format('%s=%s',n,o)..i
t=t+1
end
return e
end
local o=function(a,t,o)
local e=' LIMIT {starnum}, {endnum};'
e=string.gsub(e,'{starnum}',t)
e=string.gsub(e,'{endnum}',o)
return a..e
end
local i=function(o,e)
local a=' GROUP BY {condlist};'
local e=t(e)
return o..string.gsub(a,'{condlist}',e)
end
local h={
['number']='int(11)',
['string']='varchar(20)',
['boolean']='int(1)'
}
local h={
['limit']=o,
['group']=i
}
local function i(e)
if type(e)=='string'then
return string.format("'%s'",e)
elseif type(e)=='table'then
local e=table.concat(e,';')
return string.format("'%s'",e)
else
return e
end
end
function e.insert_data(e,n)
local e=string.gsub(c,'{tbname}',string.format('`%s`',e))
local a=''
local t=''
local o
for n,s in pairs(n)do
o=i(s)
a=a..string.format('`%s`',n)..','
t=t..o..','
end
e=string.gsub(e,'{defienks}',string.sub(a,0,string.len(a)-1))
e=string.gsub(e,'{vals}',string.sub(t,0,string.len(t)-1))
return e
end
function e.find(o,e)
local o=string.gsub(u,'{tbname}',o)
local i
if#e>0 then
i=t(e)
else
i=a(e)
end
o=string.gsub(o,'{condition}',i)
return o
end
function e.find_in_set(e,o,a)
local e=string.gsub(w,'{tbname}',e)
local t=t(a)
e=string.gsub(e,'{condkey}',o)
e=string.gsub(e,'{condlist}',t)
return e
end
function e.find_in(e,o,a)
local e=string.gsub(f,'{tbname}',e)
local t=t(a)
e=string.gsub(e,'{condkey}',o)
e=string.gsub(e,'{condlist}',t)
return e
end
function e.fetch_limitcnt(e,o,i,t)
local e=string.gsub(m,'{tbname}',string.format('`%s`',e))
e=string.gsub(e,'{starnum}',tostring(o))
e=string.gsub(e,'{endnum}',tostring(i))
if t then
e=e..a(t)
end
return e
end
function e.dele_all(e,t)
local e=string.gsub(l,'{tbname}',e)
local t=a(t)
e=string.gsub(e,'{condition}',t)
return e
end
function e.update(e,t,o,i)
local e=string.gsub(r,'{tbname}',e)
local t=s(t,i)
e=string.gsub(e,'{vallist}',t)
e=string.gsub(e,'{condition}',a(o))
return e
end
function e.group_by(e,a)
local o=string.gsub(d,'{tbname}',e)
local e=t(a)
n:dump(a,":====>>group by cond_str%s")
n:info(":====>>group by cond_str%s",e)
return string.gsub(o,'{condlist}',e)
end
function e.append_cmd(e,t,...)
e=string.sub(e,0,-2)
local a=h[t]
if not a then
n:warn("[utilrds]append not found the fun key[%s]",t)
return
end
return a(e,...)
end
return e
end)
local e={
LN=nil,
UtilRds=nil,
PoolMgr=nil,
Logger=nil,
Orm={
__index=function(e,e)
ngx.say("orm not init yet")
end
},
uuid=require("framework.libs.jit_uuid")
}
require("framework.lua_ex")
require("framework.lua_ex2")
local t=false
local a="/usr/local/openresty/nginx"
local t=function(e,...)
local a
if string.find(e,"\n")~=-1 then
a=string.gsub(e,"\n","<br> ")
end
local e=t==true and""or"<br>"
ngx.say(string.format(e..a,...))
t=true
end
local t=function(a)
local e
local t=type(a)
if t=="function"then
e=t
else
e=a
end
_stdlog(e)
end
function e.init(t,a)
e.LN=require("framework.ln")
local a=require("framework.log.init")
e.Logger=a.Logger.new()
e._initUtils()
e._initIncs()
e["RELEASE_CONF"]={
isdev=t
}
end
function e.set_ln(t,a)
if a=="src"then
e.LN:set_srcval(t)
end
end
function e._initUtils()
e.UtilRds=require("framework.utils.utilrds")
end
function e._initIncs()
e.PoolMgr=require("framework.db.poolmgr").new()
end
function e.initOrm(t)
e.Orm=require("framework.orm.init").new(t)
end
e.loaded_packages={}
local a=e.loaded_packages
function e.register(a,t)
e.loaded_packages[a]=t
end
function e.load(...)
local e={...}
assert(#e>0,"d.load() - invalid package names")
local t={}
for o,e in ipairs(e)do
assert(type(e)=="string",string.format('d.load() - invalid package name "%s"',tostring(e)))
if not a[e]then
local t=string.format("framework.decorator.%s",e)
local o=require(t)
assert(o,string.format('d.load() - package class "%s" load failed',t))
a[e]=o
end
t[#t+1]=a[e]
end
return unpack(t)
end
local n=e.load
local o
o=function(t,...)
local i=type(t)
assert(
i=="table"or i=="userdata",
string.format("d.bind() - invalid target, expected is object, actual is %s",i)
)
local i={...}
assert(#i>0,"d.bind() - package names expected")
n(...)
if not t.components_ then
t.components_={}
end
for i,e in ipairs(i)do
assert(type(e)=="string"and e~="",string.format('d.bind() - invalid package name "%s"',e))
if not t.components_[e]then
local a=a[e]
for a,e in ipairs(a.depends or{})do
if not t.components_[e]then
o(t,e)
end
end
local a=a:create()
t.components_[e]=a
a:bind(t)
end
end
return t
end
e.bind=o
function e.setmethods(o,t,e)
for a,e in ipairs(e)do
local a=t[e]
o[e]=function(e,...)
return a(t,...)
end
end
end
function e.unsetmethods(e,t)
for a,t in ipairs(t)do
e[t]=nil
end
end
return e
